<?php
namespace app\access\controller;

use tp5_lib\common\controller\TestBaseController;
use tp5_lib\access\model\RoleModel;
use tp5_lib\access\logic\RoleLogic;

/**
 * 测试RoleLogic
 * 不关联用户
 */
class RoleTestController extends TestBaseController
{
    public function index()
    {
        $logic=RoleLogic::instance();
        return $this->fetch('', ["role_list"=>$logic->getAllRoles()]);
    }
    public function create()
    {
        $data=input();
        $role_model=new RoleModel();
        $role_model->db()->insert($data);
        $this->success();
    }
    public function remove()
    {
        $code=input("code");
        $role_model=new RoleModel();
        $role_model->db()->where("code",$code)->delete();
        $this->success();
    }
    public function update()
    {
        $data=input();
        $role_model=new RoleModel();
        $role_model->db()->where("code",$data["code"])->update([
            "name"=>$data["name"],
            "parent"=>$data["parent"],
            "privilege"=>$data["privilege"],
        ]);
        $this->success();
    }
}
